/**
 * Created by dashan on 2017/3/20.
 */

var mongoose = require('mongoose');
mongoose.Promise = Promise;
mongoose.connect('mongodb://dev1.bjvca.com:27017/test2');

var PersonSchema = new mongoose.Schema({
    firstName:String,
    lastName:String
});

PersonSchema.virtual('fullName').get(function(){
    // return this.firstName + ' ||||||'+ this.lastName;
    return replay(this.firstName,this.lastName);
});

PersonSchema.set('toJson',{getter:true,virtual:true});

var Person = mongoose.model('Person',PersonSchema)
var person = new Person({
    firstName:'Sid',
    lastName:'chen'
})

console.log("user fullname:"+person.fullName);

console.log("json"+JSON.stringify(person));


function replay(first,last){
    return first+"@@@@"+last;
}

